package com.java214.elec.controller;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.java214.elec.utils.GenericTypeUtils;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

/**   
*    
* 项目名称：MyEleManagerSys   
* 类名称：BaseController   
* 类描述：   所有控制类的总父类,减少子类的麻烦处
* 创建人：君无邪   
* 创建时间：2019年11月12日 下午2:33:20   
* 修改备注：  https://www.java214.com 
* 补充描述：子类可用的最好用protected
* @version    1.0
*    
*/ 
public class BaseController<T> extends ActionSupport implements ModelDriven<T>,ServletRequestAware,ServletResponseAware {

	protected HttpServletRequest request; 
	protected HttpServletResponse response;
	
	private T entity;
	
	public BaseController() {
		// TODO Auto-generated constructor stub
			//泛型转换，目的:将对应的泛型转换成真实的对象类型	
		Class beanclass = GenericTypeUtils.getGenericSuperClass(this.getClass());
		try {
			entity =(T) beanclass.newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Override
	public T getModel() {
	
		
		return entity;
	}
	
	@Override
	public void setServletRequest(HttpServletRequest req) {
		// TODO Auto-generated method stub
		this.request=req;
	}
	@Override
	public void setServletResponse(HttpServletResponse res) {
		// TODO Auto-generated method stub
		this.response=res;
		
	}


}
